/**
 * @class 房态盘
 * @description 业务处理
 */
class service{
    
    /**
     * 构造函数
     */
    constructor(){}
    
    /**
     * 当前全部房态盘数据
     */
    roomViewCurrentData=[];

    /**
     * 改变数据
     */
    changeData=[];

    /**
     * 自定义样式字典
     */
    getCustomHodictParams={};

    /**
     * 图标字典
     */
    getDictIcoColors=[];

    /**
     * 房态盘基础默认数据
     */
    getRoomsViewAsDefault={}

    /**
     * @method 创建
     * @param {*} dataSource 数据源
     * @param {*} target DOM对象
     * @param {*} replace 是否替换
     */
    createRoomView_frameWork(dataSource,target,replace=false){
        let _targetJQ=$(target);

        if(!replace)
            _targetJQ.empty();

        let {descript1:ftpWidth='120px'}=this.getCustomHodictParams.filter(item=>item.descript2==='色块宽度')[0]||{};
        let {descript1:ftpHeight='66px'}=this.getCustomHodictParams.filter(item=>item.descript2==='色块高度')[0]||{};
        let fontSize=' font-size:'+parseInt(ftpHeight.split('px')[0])*0.2+'px ';

        let lastFloor='';
        dataSource.map((v)=>{
            let {synbcolor='',floor='',room=''}=v;
            let lineFeed=(lastFloor!=''&&lastFloor!=floor)?'<br>':'';
            if(lineFeed!=''){
                _targetJQ.append(lineFeed);
            }   
            lastFloor=floor;
            let style=`background-color:${synbcolor};width:${ftpWidth};height:${ftpHeight};`;
            let app=`<div data-floor='${floor}' id='${room}' class='rvl-ftp-member' style='${style} ${fontSize}'>`;
            let appChilds=``;
            appChilds+=this.getMemberHeader()+this.roomFn(v,'left')+this.iconFn(v)+this.getMemberFoot();
            appChilds+=this.getMemberHeader()+this.rmtypeFn(v,'left')+this.balanceFn(v)+this.getMemberFoot();
            appChilds+=this.getMemberHeader()+this.gnameFn(v,'left')+this.rmlinksFn(v)+this.getMemberFoot();
            if(!replace){
                app+=`${appChilds}</div>`;
                _targetJQ.append(app);
            }else{
                $("#"+room).empty();
                $("#"+room).css('background-color',synbcolor);
                $("#"+room).append(appChilds);
            }
        });

        return _targetJQ;
    }

    /**
     * @method 房号
     * @param {*} json 当前房号数据
     * @param {*} position 位置
     * @returns 
     */
    roomFn(json,position='right'){
        //特殊标志连通房
		let roomIco=(json.connecting&&''!=json.connecting)?'<i style="color:blue" class="fa fa-code-fork"></i>':'';
        //字体颜色
        let fontColor=(json.syntcolor&&''!=json.syntcolor)?json.syntcolor:'#2A6496';

        let htmlTemple=`<div style='color:${fontColor};flex:1;text-align:${position}'>${json.room}${roomIco}</div>`;

        return htmlTemple;
    }

    /**
     * @method 图标
     * @param {*} json 当前房号数据
     * @param {*} position 位置
     * @returns 
     */
    iconFn(json,position='right'){ 
		
        let htmltemple=`<div style='flex:1;text-align: ${position};'>`;

		//逃逸房
		if (json.Skip == '1'){
            var icoColor=this.getIcoColor("ICO_Skip");
            if(icoColor!="")
                htmltemple +=	'<div data-id="Skip" style="color:'+icoColor+'" class="room_status_skip"></div>';
            else
                htmltemple +=	'<div data-id="Skip" class="room_status_skip"></div>'; 
		}
		
		//睡眠房
		if (json.Sleep == '1'){
            var icoColor=this.getIcoColor("ICO_Sleep");
            if(icoColor!="")
                htmltemple +=	'<div data-id="Sleep" style="color:'+icoColor+'" class="room_status_sleep"></div>';
            else
                htmltemple +=	'<div data-id="Sleep" class="room_status_sleep"></div>';
		}
		
		//在住
		if (json.CheckedIn == '1'){
            var icoColor=this.getIcoColor("ICO_CheckedIn");
            if(icoColor!="")
                htmltemple +=	'<div data-id="CheckedIn" style="color:'+icoColor+'"  class="room_status_checkin"></div>'; 
            else
                htmltemple +=	'<div data-id="CheckedIn" class="room_status_checkin"></div>'; 
		}
		
		//离店
		if (json.OUTHouse == '1'){
            var icoColor=this.getIcoColor("ICO_OUTHouse");
            if(icoColor!="")
                htmltemple +=	'<div data-id="OUTHouse" style="color:'+icoColor+'" class="room_status_checkout"></div>'; 
            else
                htmltemple +=	'<div data-id="OUTHouse" class="room_status_checkout"></div>';
		}
		
		//小时房
		if (json.ishour =='1'){
            var icoColor=this.getIcoColor("ICO_Ishour");
            if(icoColor!="")
                htmltemple +=	'<i data-id="ishour" style="color:'+icoColor+'" class="fa fa-clock-o bigger-130 "></i>';
            else
                htmltemple +=	'<i data-id="ishour" style="color:blue" class="fa fa-clock-o bigger-130 "></i>';
		}
		
		//到期小时房
		if (json.ishour >"1"){
            var icoColor=this.getIcoColor("ICO_IshourDep");
            if(icoColor!="")
                htmltemple +=	'<i style="color:'+icoColor+'" data-id="ishour" class="fa fa-clock-o bigger-130"></i>';
            else
                htmltemple +=	'<i style="color:red" data-id="ishour" class="fa fa-clock-o bigger-130"></i>';
		}
		
		//凌晨  
		if (json.ismorning =='1'){
            var icoColor=this.getIcoColor("ICO_Ismorning");
            if(icoColor!="")
                htmltemple +=	'<i data-id="ismorning" style="color:'+icoColor+'" class="fa fa-moon-o bigger-130"></i>';
            else
                htmltemple +=	'<i data-id="ismorning" style="color:red" class="fa fa-moon-o bigger-130"></i>';
		}
		
		//预离
		if (json.Depaturs == '1'){
            var icoColor=this.getIcoColor("ICO_Depaturs");
            if(icoColor!="")
                htmltemple +=	'<i data-id="Depaturs" style="color:'+icoColor+'" class="fa fa-arrow-right bigger-130"></i>';
            else
                htmltemple +=	'<i data-id="Depaturs" style="color:purple" class="fa fa-arrow-right bigger-130"></i>';
		}
		
		//同住房
		if (json.shared == '1'){
            var icoColor=this.getIcoColor("ICO_Shared");
            if(icoColor!="")
                htmltemple +=	'<div ata-id="shared" ata-id="shared" style="color:'+icoColor+'" class="room_status_share"></div>'; 
            else
                htmltemple +=	'<div ata-id="shared" ata-id="shared" class="room_status_share"></div>'; 
		}
		
		//占用预抵
		if (json.O_Arrival == '1'){
            var icoColor=this.getIcoColor("ICO_O_Arrival");
            if(icoColor!="")
                htmltemple +=	'<div ata-id="O_Arrival" style="color:'+icoColor+'" class="room_status_oarrival"></div>'; 
            else
                htmltemple +=	'<div ata-id="O_Arrival" class="room_status_oarrival"></div>'; 
		}
		
		//锁房
		if (json.ass != ''&&json.ass.indexOf("选房占房")>-1){
            var icoColor=this.getIcoColor("ICO_Ass");
            if(icoColor!="")
                htmltemple +=	'<i ata-id="ass" style="color:'+icoColor+'" class="fa fa-unlock bigger-100"></i>';
            else
                htmltemple +=	'<i ata-id="ass" style="color:red" class="fa fa-unlock bigger-100"></i>';
		}
		
		//做房
		if (json.ass != ''&&json.ass.indexOf("选房占房")==-1){
            var icoColor=this.getIcoColor("ICO_AssZ");
            if(icoColor!="")
                htmltemple +=	'<i ata-id="ass" style="color:'+icoColor+'" class="fa fa-lock bigger-100"></i>'; 
            else
                htmltemple +=	'<i ata-id="ass" style="color:green" class="fa fa-lock bigger-100"></i>'; 
		}
		
		//预抵
		if ((Number(json.V_Arrival)+Number(json.O_Arrival)) >0){
            var icoColor=this.getIcoColor("ICO_Arrival");
            if(icoColor!="")
                htmltemple +=	'<i ata-id="V_Arrival" style="color:'+icoColor+'" class="fa fa-arrow-left bigger-130"></i>';
            else
                htmltemple +=	'<i ata-id="V_Arrival" style="color:green" class="fa fa-arrow-left bigger-130"></i>';
		}
		
		//远期预抵
		if (json.F_Arrival == '1'){
            var icoColor=this.getIcoColor("ICO_F_Arrival"); 
            if(icoColor!="")
                htmltemple +=	'<i ata-id="F_Arrival" style="color:'+icoColor+'" class="ace-icon fa fa-chevron-left green bigger-120"></i>'; 
            else
                htmltemple +=	'<i ata-id="F_Arrival" class="ace-icon fa fa-chevron-left green bigger-120"></i>'; 
		}
		
		//VIP
		if (json.vip!=""){
			var icoColor=this.getIcoColor("ICO_Vip"); 
			if(icoColor!="")
				htmltemple +=	'<i title="'+json.vip+'" class="ace-icon fa fa-vimeo bigger-120" style="color:'+icoColor+'"></i>';
			else
				htmltemple +=	'<i title="'+json.vip+'" class="ace-icon fa fa-vimeo bigger-120" style="color:red"></i>';  
		}
		
		//房间管理
		if (json.hasOwnProperty("ho_rooms_text1")&&json.ho_rooms_text1!=""&&json.ho_rooms_text1!="null"&&json.ho_rooms_text1!=null){
			var icoColor=this.getIcoColor("ICO_ho_rooms_text1");
			if(icoColor!="")
				htmltemple +=	'<i title="'+json.ho_rooms_text1+'" class="fa fa-question-circle-o bigger-120"  style="color:'+icoColor+'"></i>';
			else
				htmltemple +=	'<i title="'+json.ho_rooms_text1+'" class="fa fa-question-circle-o bigger-120"  style="color:red"></i>';
		}
		
		if(json.market=="COM")	 
            htmltemple +='<i data-id="COM" style="color:#a0a0a0 !important;" class="ace-icon fa fa-circle bigger-30"></i>'
		if(json.market=="HU")	
            htmltemple +='<i data-id="HU" style="color:#333333 !important;" class="ace-icon fa fa-circle bigger-30"></i>'
		
		//尾标
		htmltemple += '</div>';
			
		return htmltemple; 

	}

    /**
     * @method 房型
     * @param {*} json 当前房号数据
     * @param {*} position 位置
     */
    rmtypeFn(json,position='right'){
        let htmlTemple=`<div style="color:${json.syntcolor||'#2A6496'};flex:1;text-align:${position}">${json.rmtype_c}</div>`;
        return htmlTemple;
    }

    /**
     * @method 余额
     * @param {*} json 当前房号数据
     * @param {*} position 位置
     */
    balanceFn(json,position='right'){
        let htmlTemple=``;
        if(json.balance!="0.00"&&json.balance!="0"){
			htmlTemple =`<div class="red" style='flex:1;text-align:${position}'>${json.balance}</div>`;
		} 
        return htmlTemple
    }

    /**
     * @method 名称
     * @param {*} json 当前房号数据
     * @param {*} position 位置
     */
    gnameFn(json,position='right'){
        let style=`overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color:${json.syntcolor||"#2A6496"}`;
        let anotherText='';
        if(json.party!="0"){
            anotherText='✱';
        }else if(json.grno!="0"){
            anotherText='@';
        }

        return `<div title="${json.gname}" style="${style}">${anotherText}${json.gname}</div>`;
    }

    /**
     * @method 备注
     * @param {*} json 当前房号数据
     * @param {*} position 位置
     */
    rmlinksFn(json,position='right'){
        let htmlTemple=`<div style='flex:1;text-align:${position}'>`;
        if (json.trace == '1'){
			htmlTemple += '<span class="red"><i class="fa fa-bell light-red bigger-120"></i></span>'
		}
		if (json.trace_ok == '1'){
			htmlTemple += '<span class="green"><i class="fa fa-bell-o green bigger-120"></i></span>'
		}

        htmlTemple+=`${json.rmlinks}</div>`; 

        return htmlTemple;
    }

    /**
     * @method 获取成员头部DOM
     * @returns 
     */
     getMemberHeader(){
        return `<div class='rvl-ftp-member-item'>`;
    }

    /**
     * @method 获取成员结束DOM
     * @returns 
     */
    getMemberFoot(){
        return `</div>`;
    }

    /**
     * @method 获取图标颜色
     * @param {*} scode 图标编码
     * @returns 颜色
     */
    getIcoColor(scode){ 
		var returnValue="";
		var icoColors=this.getDictIcoColors; 
		$(icoColors).each(function(k,v){
			if(v.code==scode)
				returnValue= v.descript1;
		});
		return returnValue;
	}


    /**
     * @method 房务表格
     * @param {*} data 数据
     * @param {*} target DOM
     * @param {*} callBack 双击回调函数
     */
    makeHouseKeepingList(data,target,dbBack){
        let _t=this;
        let grid_selector=$(target);
        grid_selector.jqGrid({
			datatype : "local",
			data:data,
			height : $(window).height()-400,
			colNames : ["","","","","","","","","","","","","","","","","","",""],
			colModel : [{
				name : "c_sort",
				index : "c_sort",
				width:30,
			},{
				name : "title1",
				index : "title1",
				formatter : function(cellvalue,options,rowObject){
					var str ="";
					if(rowObject.status==0){
						str = rowObject.title;
					}else{
						str = '<font color="blue">'+rowObject.title+'</font>'
					}
					return str;
				},
			},{
				name : "clean",
				index : "clean",
				hidden : true,
			},{
				name : "dirty",
				index : "dirty",
				hidden : true,
			},{
				name : "oo",
				index : "oo",
				hidden : true,
			},{
				name : "os",
				index : "os",
				hidden : true,
			},{
				name : "co",
				index : "co",
				hidden : true,
			},{
				name : "v_exp_arr",
				index : "v_exp_arr",
				hidden : true,
			},{
				name : "ci",
				index : "ci",
				hidden : true,
			},{
				name : "stay",
				index : "stay",
				hidden : true,
			},{
				name : "due_out",
				index : "due_out",
				hidden : true,
			},{
				name : "o_exp_arr",
				index : "o_exp_arr",
				hidden : true,
			},{
				name : "touch_up",
				index : "touch_up",
				hidden : true,
			},{
				name : "vacant",
				index : "vacant",
				hidden : true,
			},{
				name : "occupied",
				index : "occupied",
				hidden : true,
			},{
				name : "rm_status",
				index : "rm_status",
				hidden : true,
			},{
				name : "last_night",
				index : "last_night",
				hidden : true,
			},{
				name : "sleep",
				index : "sleep",
				hidden : true,
			},{
				name : "skip",
				index : "skip",
				hidden : true,
			}],    	
			scroll : true,
			viewrecords : true,
			altRows : true, 
			shrinkToFit : true,
			altRows : true,
			scrollrows:true,
	        ondblClickRow: function(rowid) { 
	        	dbBack(_t.getHouseKeepingSel(target));
	        },
			gridComplete:function(){
                let ids = $(this).jqGrid('getDataIDs');
				$(this).jqGrid('setSelection',ids[0]);
				$(this).closest('.ui-jqgrid-view').find('div.ui-jqgrid-hdiv').hide();
				$(this).closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
			}	
		});
        grid_selector.jqGrid("setGridWidth",$("#houseKeeping").width());
    }

    /**
     * @method 获取房务表格选中行条件
     * @param {*} target DOM
     * @returns 
     */
    getHouseKeepingSel(target){
        let grid_selector=$(target);
        let rowId=$(grid_selector).jqGrid('getGridParam','selrow');
        let rowData = $(grid_selector).jqGrid("getRowData",rowId);
        delete rowData["c_sort"];
        let title1=rowData.title1;
        return this.houseKeepingFilters[title1]||{}
    }
}

export default new service();


